<template>
	<view v-if="bidding_info">
		<view class="bidding" >
			<image :src="$util.img(bidding_info.sku_image)" mode="" class="bidding_img"></image>
			<view class="bidding_left">
				<text class="bidding_left_co">{{bidding_info.pintuan_name}}</text>
				
				<view class="bidding_left_color" >
					<text style="margin-right: 28rpx;" v-for="(item,index) in sku_spec_format"	>{{item.spec_name}}:{{item.spec_value_name}}</text>
				</view>
				<view class="bidding_left_qian">
					<text>¥ {{bidding_info.price}}</text>
				</view>
			</view>
		</view>
		
		<view class="bidding_herfer">
			<text>截止时间</text>
			<view class="bidding_herfer_view">
				{{$util.timeStampTurnTime(bidding_info.bidding_end_time)}}
			</view>
		</view>

		<view class="bidding_list">
			<view class="bidding_list_anv" v-for="(level_rule ,index) in bidding_level_rule" :key="index">

				<view class="scroll-view-item">
					<view class="list_heder">
						
						<text>竞标等级{{index+1}}</text>
		
						<view class="bidding_list_ring">
							<radio  @click="radionTo(level_rule,index)"  :checked="selected_index==index?true:false"/>
						</view>
					</view>
					<view class="list_bodyw"></view>
					<view class="PopWindow_dyuag">
						<view class="PopWindow_dyuag_sdad">
							<view class="list_num">数量(件)</view>
							<text class="list_num_dyg">{{level_rule.bidding_num}}</text>
						</view>
						<view class="PopWindow_dyuag_sdad">
							<view class="list_num">成本价(元)</view>
							<text class="list_num_dyg">{{Number(level_rule.cost_price).toFixed(2)}}</text>
						</view>

						<view class="PopWindow_dyuag_sdad">
							<view class="list_num">拼团价(元)</view>
							<text class="list_num_dyg">{{Number(level_rule.pintuan_price).toFixed(2)}}</text>
						</view>

						<view class="PopWindow_dyuag_sdad">
							<view class="list_num">成团人数</view>
							<text class="list_num_dyg">{{level_rule.pintuan_num}}</text>
						</view>
					</view>
				</view>
	
					
				</view>
			</view>
						<view class="PopWindow_botton" style="height: 120rpx;">
		</view>
		<view class="bidding_footer">
			<view class="bidding_footer_text">
				<!-- <view class="daasdgrg">预期获利：<text>{{earn_profit}}</text>元</view> -->
				<view class="bidding_fooad">竞标金额：<text>￥{{total_sum }}</text></view>
				<button type="default" @click="mergePay">提交</button>
			</view>
		</view>


		<uni-popup ref="payPassword" :custom="true" :maskClick="false">
			<view class="pay-password">
			<block v-if="isset == 0">
				<view class="title">为了您的账户安全,请先设置您的支付密码</view>
				<view class="tips">可到"个人中心","个人资料","支付密码"中设置</view>
				<view class="btn ns-border-color ns-bg-color" @click="setPayPassword">立即设置</view>
				<view class="btn white ns-border-color ns-text-color" @click="noSet">暂不设置</view>
			</block>
			<block v-if="isset == 1">
				<view class="title">请输入支付密码</view>
				<view class="password-wrap">
					<myp-one :maxlength="6" :is-pwd="true" @input="input" ref="input" :auto-focus="isFocus" type="box"></myp-one>
					<view class="align-right"><text class="ns-text-color ns-font-size-sm forget-password" @click="setPayPassword">忘记密码</text></view>
				</view>
			</block>
			</view>
		</uni-popup>
	</view>

</template>

<script>
	import mypOne from '@/components/myp-one/myp-one.vue';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import nsSwitch from '@/components/ns-switch/ns-switch.vue';
	export default {
		data() {
			return {
				bidding_info: null,
				bidding_id: 0,
				sku_spec_format: {},
				bidding_level_rule: [],
				suanjis: 0, //获利
				iuasdhiid: 0, //总金额
				isFocus: false,
				orderCreateData: {
					pay_password: '',
				},
				selected_index:0,
				total_sum:0,
				earn_profit:0,
				isset: -1,
			}
		},
		components: {
			mypOne,
			uniPopup,
			nsSwitch
		},
		onLoad: function(data) {
			this.bidding_id = data.bidding_id || 0;
			this.getBiddingInfo();
			
		},
		onShow() {
			// 刷新多语言
			this.isSetPayPassword();
			this.$langConfig.refresh();
		},
		methods: {
			isSetPayPassword() {
				this.$api.sendRequest({
					url: '/api/member/issetPayPassword',
					success: res => {
						if (res.code >= 0) {
							this.isset = res.data.isset;
						}
					}
				})
			},
			getBiddingInfo() {
				this.$api.sendRequest({
					url: '/platformpintuan/api/pintuanbidding/biddingdetail',
					data: {
						bidding_id: this.bidding_id,
						page:this.page,
						page_size:this.page_size
					},
					success: res => {
						if (res.code >= 0) {
							this.bidding_info = res.data
							this.sku_spec_format = JSON.parse(res.data.sku_info.sku_spec_format)
							this.bidding_level_rule = res.data.bidding_level_rule;
							this.radionTo(this.bidding_level_rule[0], 0);
						}
					}
				})
			},

			//单选
			radionTo(item,index) {
				this.selected_index = index;
				let moutton = item	
				
				this.earn_profit = ((moutton.pintuan_price-moutton.cost_price)*moutton.bidding_num).toFixed(2)
				this.total_sum = item.bidding_money.toFixed(2)//总价
			},
			mergePay() {
		
				if (this.selected_index==-1) {
				this.$util.showToast({
					title:'请选择竞标等级',
					mask:true,
					duration:2000
				})
				}else{
					if(Number(this.total_sum) == 0){
						this.$api.sendRequest({
							url: '/platformpintuan/api/pintuanbidding/enter',
							data: {
								bidding_id: this.bidding_id,
								pay_password: '',
								bidding_level:this.selected_index
							},
							success: res => {
								if (res.code >= 0) {
									this.$util.showToast({
										title: "参与竞标成功，请耐心等待审核"
									});
									setTimeout(() => {
										this.$util.redirectTo('/pages/member/index/index');
									},2000);
							    }else{
									this.$util.showToast({
										title: res.message
									});
							    }
								this.$refs.payPassword.close();
							},
							fail: res => {
								uni.hideLoading();
							}
						})
					}
					else {
						this.openPasswordPopup() 
					}
				}
			},
			openPasswordPopup() {
				this.$refs.payPassword.open();
				setTimeout(() => {
					this.isFocus = true;
				}, 0)
			},
			//支付
			input(pay_password) {
				let that = this;
				if (pay_password.length == 6) {
					uni.showLoading({
						title: '支付中...',
						mask: true
					})
					this.$api.sendRequest({
						url: '/platformpintuan/api/pintuanbidding/enter',
						data: {
							bidding_id: this.bidding_id,
							pay_password,
							bidding_level:this.selected_index
						},
						success: res => {
							if (res.code >= 0) {
								this.$util.showToast({
									title: "参与竞标成功，请耐心等待审核"
								});
								setTimeout(() => {
									this.$util.redirectTo('/pages/member/index/index');
								},2000);
						    }else{
								this.$util.showToast({
									title: res.message
								});
						    }
							this.$refs.payPassword.close();
						},
						fail: res => {
							uni.hideLoading();
						}
					})
				}
			},
			/**
			 * 设置支付密码
			 */
			setPayPassword() {
				this.$util.redirectTo('/otherpages/member/pay_password/pay_password', {
					back: '/promotionpages/platformpintuan/bidding_detail/bidding_detail?bidding_id=' + this.bidding_id,
				});
			},
			/*
			*  暂不设置密码
			* */
			noSet() {
				this.$refs.payPassword.close();
			}
		}
	}
</script>

<style lang="scss">
	.bidding {
		display: flex;
		margin: 22rpx 30rpx 0 30rpx;
		background-color: #FFFFFF;
		height: 250rpx;

		.bidding_img {
			width: 182rpx;
			height: 182rpx;
			display: flex;
			flex-direction: row;
			margin: 32rpx 0 0 32rpx;

		}

		.bidding_left {
			display: flex;
			flex-direction: column;
			margin: 34rpx 0 0 22rpx;

			.bidding_left_co {
				width: 428rpx;
				height: 68rpx;
				line-height: 40rpx;
				font-size: 28rpx;
				display: flex;
				flex-direction: column;
				font-family: PingFang-SC-Medium;
			}

			.bidding_left_color {
		
				margin: 26rpx 0 0 0;
				color: #909399;
				font-size: 26rpx;
				text{
					display: inline-block;
					
				}
			}

			.bidding_left_qian {
				display: flex;
				flex-wrap: row;
				justify-content: flex-start;
				color: #FF4544;
				font-size: 24rpx;
				margin: 14rpx 0 0 0;
			}
		}
	}

	.bidding_herfer {
		margin: 20rpx 28rpx 0 30rpx;
		background-color: #FFFFFF;
		height: 90rpx;
		display: flex;
		position: relative;

		text {
			margin: 26rpx 0 0 40rpx;
			font-size: 28rpx;
			line-height: 40rpx;
		}

		.bidding_herfer_view {
			height: 28rpx;
			position: absolute;
			top: 20rpx;
			right: 36rpx;
		}
	}

	.bidding_list {
		margin: 0 17px 0 28rpx;

		.bidding_list_anv {
			width: 100%;

			.scroll-view-item {
				height: 224rpx;
				width: 100%;
				margin-top: 20rpx;
				background-color: #FFFFFF;

				.list_heder {
					color: #000000;
					font-size: 30rpx;
					font-weight: 500;
					display: flex;
					justify-content: row;
					padding: 20rpx 0 0 31rpx;
				}

				.bidding_list_ring {
					position: absolute;
					right: 80rpx;
				}

				.list_bodyw {
					display: inline-block;
					height: 2rpx;
					background-color: #EEEEEE;
					display: flex;
					justify-content: center;
					margin: 29rpx 34rpx 0 30rpx;
				}

				.PopWindow_dyuag {
					display: flex;
					justify-content: flex-start;
					align-items: flex-start;
					align-content: space-between;

					.PopWindow_dyuag_sdad {
						width: 35%;

						.list_num {
							margin: 16rpx 0 0 30rpx;
							color: #909399;
							font-size: 24rpx;
						}

						.list_num_dyg {
							margin-left: 26rpx;
							text-align: center;
							font-size: 32rpx;
							color: #333333;
							font-weight: 500;
						}
					}
				}
			}
		}
	}

	.bidding_footer {
		position: fixed;
		bottom: 0;
		height: 100rpx;
		width: 100%;
		background-color: #FFFFFF;
		font-size: 28rpx;

		.bidding_footer_text {
			display: flex;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 32rpx 0 0 30rpx;

			.daasdgrg {
				font-size: 28rpx;
				font-weight: 300;
				text {
					color: #FF4544;
				}
			}

			.bidding_fooad {
				//margin-left: 7%;
				text {
					color: #FF4544;
					font-size: 28rpx;
				}
			}

			button {
				width: 160rpx;
				height: 60rpx;
				background-color: #FF4544;
				color: #FFFFFF;
				line-height: 60rpx;
				position: absolute;
				right: -16rpx;
				top: 24rpx;
			}
		}
		
	}

	.pay-password {
		width: 80vw;
		background: #fff;
		level_rule-sizing: border-level_rule;
		border-radius: 10rpx;
		overflow: hidden;
		padding: 60rpx 40rpx;
		transform: translateY(-200rpx);

		.title {
			font-size: 28rpx;
			text-align: center;
		}

		.tips {
			font-size: 24rpx;
			color: #999;
			text-align: center;
		}

		.btn {
			width: 60%;
			margin: 0 auto;
			margin-top: 30rpx;
			height: 70rpx;
			line-height: 70rpx;
			border-radius: 70rpx;
			color: #fff;
			text-align: center;
			border: 1px solid #ffffff;

			&.white {
				margin-top: 20rpx;
				background-color: #fff !important;
			}
		}

		.password-wrap {
			padding-top: 20rpx;
			width: 90%;
			margin: 0 auto;

			.forget-password {
				margin-top: 20rpx;
				display: inline-block;
			}
		}
	}
</style>
